#pragma once
#include "FMDBApplication.h"

class FMDBConnection
{
public:
	enum ConnectionStatus
	{
		csOpened,
		csClosed,
		csError
	};
	FMDBConnection(FMDBApplication* pOracleDB);
	FMDBConnection(void);
	~FMDBConnection(void);

	void Open();
	void Close();
	void GetDBServerVersion(text* buff,ub4 BuffSize);
	void GetDBClientVersion(sword *verMajor,sword *verMinor,sword *verUpdate,sword *verPatch,sword *verPort);
	ConnectionStatus GetStatus(){return m_ConnectionStatus;}

	//transaction
	void Commit(ub4 Mode=OCI_DEFAULT);
	void Rollback(ub4 Mode=OCI_DEFAULT);
	void BeginTransaction(ub4 Mode=OCI_TRANS_NEW);


public://properties

	//oci environment handle
	FMDBApplication *GetFMDBApp(){return m_pOracleDB;}
	
	void SetFMDBApp(FMDBApplication *val)
	{
		m_pOracleDB=val;
		m_pOCIErr=val->GetOCIErrorHandle();
	}

	//session statement cache
	int GetStatementCache(){return m_stmtCache;}
	void SetStatementCache(int val)
	{
		if (val<-1){val=-1;}//statement cache >=-1
		m_stmtCache=val;
	}

	//FMDBApplication error handle, read only
	OCIError *GetOCIErrorHandle(){return m_pOCIErr;}

	//session handle,read only
	OCISvcCtx *GetHandle(){return m_pSvcCtx;}

	void SetDiagnosticAttributes (TCHAR (*AttriValue)[64],ub4 *AttriCode,short AttriNumber);

private:
	void Init( FMDBApplication* pOracleDB );

private:
	FMDBApplication *m_pOracleDB;	//oci environment handle
	OCISvcCtx *m_pSvcCtx;			//oci session
	int m_stmtCache;				//statement cache for this session,-1 means use default
	OCIError *m_pOCIErr;//oci error handle

	TCHAR (*m_pDiagValues)[64];//diagnostic attributes values
	ub4 *m_pDiagCodes;//diagnostic attributes codes
	short m_iDiagNum;//number of diagnostic attributes
	ConnectionStatus m_ConnectionStatus;
};

